package com.wjk.Demo06;

import java.util.ArrayList;

public class Test01 {
    public static void main(String[] args) {
        ArrayList<Animal> list = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            list.add(new Dog());
        }
        for (int i = 0; i < 5; i++) {
            list.add(new Cat());
        }
        for (int i = 0; i < list.size(); i++) {
            list.get(i).eat();
            if (list.get(i) instanceof Dog) {
                Dog d = (Dog) list.get(i);
                d.watchHome();
            }
            if (list.get(i) instanceof Cat) {
                Cat c = (Cat) list.get(i);
                c.catchMouse();
            }
        }
    }

    public static void useAnimal(Animal a) {
        a.eat();
    }
}

abstract class Animal {
    public abstract void eat();
}

class Cat extends Animal {
    @Override
    public void eat() {
        System.out.println("猫吃鱼");
    }

    public void catchMouse() {
        System.out.println("猫抓老鼠");
    }
}

class Dog extends Animal {
    @Override
    public void eat() {
        System.out.println("狗吃肉");
    }

    public void watchHome() {
        System.out.println("狗看家");
    }
}